<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>学生管理登陆界面</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
<%--	<link rel="stylesheet" type="text/css" href="/css/login.css"/>--%>
	  <link rel="stylesheet" type="text/css" href="<%=basePath%>css/login.css"/>
	  <script src="<%=basePath%>js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
			<div id="main">
			
				<form action="<%=basePath%>user/login" method="post" onsubmit="return Login.checkfn(this)">
					<fieldset>
						<legend>用户登陆</legend>
							<label for="j_username"><span  class="iconfont">
			&#xe68a;
		</span>用户名：</label>
							<input type="text" name="userName" id="userName" value="" placeholder="请输入用户名" />
							
							<label for="j_password"><span  class="iconfont">
								&#xe60f;
							</span>密&nbsp;&nbsp;&nbsp;码：</label>
							<input type="password" name="password" id="j_password" value="" placeholder="请输入密码" />
						
								<c:if test="${code == 'ERR002' || code == 'ERR003'}" var="msg2">
									<span id="erorr">账号或者密码错误，请重新登陆</span>
								</c:if>
								<c:if test="${code == '000000' }" var="msg2">
									<span id="succ">注册成功，请重新登陆</span>
								</c:if>

							<input type="submit" name="" id="" value="登陆" />
							<div id="content">
								<input type="button" value="注册" onclick="regist()"/>
								<input type="reset"  value="重置"/>
							</div>
					</fieldset>
					
				</form>
			</div>
		
<!-- 		<script src="js/login.js" type="text/javascript" charset="utf-8"></script> -->
	</body>
	<script>
	    var check = function(){
	    	var userName = document.querySelector('#userName').value;
	    	var password = document.querySelector('#j_password').value;
	    	if(!userName||!password){
	    		alert("用户名和密码不能为空，请重新输入");
	    		return false;
	    	}
	    }
	    function regist(){
	    	
	    	var userName = document.querySelector('#userName').value;
	    	var password = document.querySelector('#j_password').value;
	    	if(!userName||!password){
	    		alert("用户名和密码不能为空，请重新输入");
	    		return false;
	    	};
	    	$.ajax({
				type:"get",
				url:"<%=basePath%>userRegist/regist",
				data:{"userName":userName,"password":password},
				success:function(data) {
					if('000000'==data){
						alert("恭喜您注册成功，请重新登录");
						$('#userName').val("");
					}else{
						alert("用户名已经被占用，请重新输入");
					}
				}
			});
	    }
	    var Login={
	    	checkfn : check, 
	    }
	    
	    
	</script>
</html>
